using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using WPCoco;
using WPCoco.Tasks;
using WPCoco.Graphics;
using WPCoco.UI;
using WPCoco.Controllers;

namespace HelloWorldDemo.Scenes
{
    public class MainScene : Scene
    {
        public MainScene()
        {
            // Creating one label for the "Hello Word"
            SpriteFontLabel label1 = new SpriteFontLabel(font1);
            label1.Text = "Hello World"; 
            label1.Anchor = new Vector2(1, 0.5f);
            label1.Position = Screen.Center - new Vector2(100, 0);
            label1.Color = Color.Transparent;
            label1.DropShadow = true;

            AddNode(label1);  // Dont forget adding the nodes to the scene

            label1.RunTask(new EaseExponentialOut(
                                new TimeSpawn(
                                    new MoveTo(Screen.Center + new Vector2(170, 0), 1),
                                    new FadeIn(1))));

            // Creating one label for "This is a demo for WPCoco"
            SpriteFontLabel label2 = new SpriteFontLabel(font1);
            label2.Text = "This is a demo for WPCoco";
            label2.FontScaleFactor = 0.4f; // This scale down the font but not the node
            label2.Anchor = new Vector2(1, 0.5f);
            label2.Position = label1.Position + new Vector2(-150, 60);
            label2.DropShadow = true;
            AddNode(label2);

            label2.RunTask(new EaseExponentialOut(
                            new TimeSpawn(
                                new MoveTo(Screen.Center + new Vector2(170, 60), 1),
                                new FadeIn(1))));

            // Create Logo button
            UIButton logo = new UIButton(Coco.Load<Texture2D>("Logo"));
            logo.Position = new Vector2(3 * Screen.Width / 4 + 95, Screen.Height / 2 + 20);
            logo.RunTask(new Sequence(
                            new Transparent(),
                            new Delay(0.8f),
                            new Spawn(
                                new FadeIn(0.1f),
                                new EaseExponentialOut(new MoveBy(new Vector2(-45,0), 0.8f)))));
            
            // Create a texture node for the button
            TextureNode node = new TextureNode(logo);
            node.Sampler = SamplerState.PointClamp; // Set sampler to Point for pixelate effect
            node.ContentScale = 0.03f; // Set initial "Content Scale" to 2%
            // Animate the "Content Scale" to 100%, after a delay 
            node.RunTask(new Sequence(
                            new Delay(1f),
                            new EaseExponentialIn(
                            new FloatAnimation("ContentScale", 0.03f, 1, 0.5f)),
                            new ActionTask(() => { node.Sampler = null; }))); // Here we restore the sampler to default
            AddNode(node);

            // We register in action event an animation that pixelate and depixelate the logo
            logo.Action += (o, e) =>
            {
                node.StopTasks();
                node.RunTask(new Sequence(
                    new ActionTask(() => { node.Sampler = SamplerState.PointClamp; }), // Set sampler to PointClamp
                    new EaseExponentialOut(new FloatAnimation("ContentScale", 1f, 0.05f, 0.5f)),
                    //new Delay(0.3f),
                    new EaseExponentialIn(new FloatAnimation("ContentScale", 0.05f, 1f, 0.5f)),
                    new ActionTask(() => { node.Sampler = null; }))); // Dont forget to restore to default
                Coco.SetFullScreen();
            };

            // Activate the Touch Screen
            ControllerManager.Shared.TouchScreen.Enabled = true;
            // Create and "UI Responder Controller" for this scene 
            UIResponderController ctlr = new UIResponderController(this);
            // Add button to chain of touch events
            ctlr.AddResponder(logo);
        }

        // Loading our font
        static SpriteFont font1 = Coco.Load<SpriteFont>("SpriteFont1");
    }
}
